﻿using System;
using System.Linq;
using System.IO;



public static class PathStorage
{
    //static methods
    public static void SavePath(Path path)
    {
        try
        {
            using (StreamWriter writer = new StreamWriter("../../../pathOut.txt"))
            {
                for (int i = 0; i < path.PathList.Count; i++)
                {
                    writer.WriteLine(path.PathList[i].ToString());
                }
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
    public static Path LoadPath()
    {
        Path path = new Path();
        try
        {
            using (StreamReader reader=new StreamReader("../../../pathIn.txt"))
            {
                string line = reader.ReadLine();
                while (line!=null)
                {
                    string[] separators=new string[]{" ",",",";",")","(","Point"};
                    string[] split = line.Split(separators,StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < split.Length - 2; i += 3)
                    {
                        Point3D pointToAdd = new Point3D(int.Parse(split[i]),int.Parse(split[i+1]),int.Parse(split[i+2]));
                        path.AddPoint(pointToAdd);
                    }
                    line = reader.ReadLine();
                }
            }
        }
        catch (Exception)
        {
            
            throw;
        }
        return path;
    }

}
